<template>
	<view class="mainpadding2" style="padding-bottom: 150rpx;">
		<u-navbar title="客戶管理" placeholder autoBack>
			<view class="flexright xiaohui" slot="right">
				<view class="toprightbtn" @click="jumpdetail('/pages/workbench/wuliaoglcg?id=',1)">新增月收</view>
			</view>
		</u-navbar>
		<view class="searchBox  flexbetween margin_top">
			<view class="flexleft" style="width: 100%;">
				<u-icon name="search" color="#B5B5B5" size="20"></u-icon>
				<view class="margin_left1" style="font-size: 24rpx;font-weight: 500;color: #B5B5B5;">請輸入搜索内容</view>
			</view>
			<view class="searchBtn flexcenter">
				<u-icon name="scan" color="#333" size="20"></u-icon>
			</view>
		</view>
		<view class="flexcenter" v-if="!list.length">
			<view class="placeholderimage" style="margin-top: 100rpx;" ></view>
		</view>
		<view class="ffffff mainpadding_top radius boxshadow" v-for="(item,index) in list" :key="item.id" @click="selectitem(item)">
			<view class="flexleft" >
				<image :src="item.avatar" mode="" class="headimg margin_right" style="min-width: 80rpx;"></image>
				<view style="width: 100%;">
					<view class="flexbetween" style="width: 100%;">
						<view class="flexleft main_size bold hei_text">
							<view class="margin_right">{{item.name}}</view>
							<view class="girl" v-if="item.gender"></view>
							<view class="boy" v-else></view>
						</view>
						<view class="main_size bold hei_text">生日：{{item.birthday}}</view>
					</view>
					<view class="flexbetween margin_top1">
						<view class="flexleft">
							<view class="xiaohui ">{{maskMiddle(item.phone)}}</view>
							<view class="copyimg" @click.stop="copy(item.phone)"></view>
						</view>
						<view class="main_size bold hei_text">區域：{{item.addre}}</view>
					</view>
				</view>
			</view>
			<template v-if="type">
				<u-icon name="checkmark-circle" color="#999" v-if="!item.ischeck" size="28"></u-icon>
				<u-icon name="checkmark-circle-fill" color="#ffb800" v-if="item.ischeck" size="28"></u-icon>
			</template>
			<view class="bghui mainpadding_top flexbetween">
				<view>
					<text class="xiaohei bold">累計訂單：</text>
					<text class="xiaohong bold">{{item.order_count}}</text>
				</view>
				<view>
					<text class="xiaohei bold">累計消費：</text>
					<text class="xiaohong bold">${{item.money_count}}</text>
				</view>
			</view>
			<view class="flex1">
				<view class="flexbetween margin_top1" @click.stop="jumpdetail(item)">
					<view class="hong_text">餘額：{{item.money}}</view>
					<view class="listbtnhuang">儲值詳情</view>
				</view>
			</view>
		</view>
		<view class="posibottom mainpadding" v-if="type">
			<view class="submitbtn" @click="submit">確認</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: '',
				type: "", //1优惠券，2免運券
				listid: ""
			}
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type
				this.listid = options.id
			}
			this.get()
		},
		methods: {
			selectitem(item){
				if(this.type){
					item.ischeck = !item.ischeck
				}
				uni.navigateTo({
					url:"/pages/workbench/kehuxfjl?id="+item.id
				})
			},
			jumpdetail(item){
				uni.navigateTo({
					url:'/pages/workbench/chuzhixq?id='+item.shop_id+"&allmoney="+item.money+"&user_id="+item.user_id
				})
			},
			async get() {
				let url = "/api/shop/yhkehulist"
				if(this.type==2){
					url = "/api/shop/mykehulist"
				}
				let res = await this.http.request(url, "POST", {
					shop_id: uni.getStorageSync("shop_id"),
					id:this.listid
				})
				if (res.code == 1) {
					res.data.forEach(item => {
						item.avatar = this.imgUrlUser + item.avatar
						this.$set(item, "ischeck", false)
					})
					this.list = res.data
				} else if (res.code == 0) {
					this.http.toast(res.msg);
				} else {
					this.http.toast('暫無數據');
				}
			},
			async submit() {
				let arr = []
				this.list.forEach(item => {
					if (item.ischeck && item.user_id) {
						arr.push(item.user_id)
					}
				})
				if (arr.length == 0) {
					this.http.toast("請選擇客戶")
					return false
				}
				let datamsg = {
					shop_id: uni.getStorageSync("shop_id"),
					id: this.listid,
					user_ids: arr.join()
				}
				let url = "/api/shop/sendrall"
				if (this.type == 2) {
					url = "/api/shop/sendship"
				}
				let res = await this.http.request(url, 'POST', datamsg)
				if (res.code == 1) {
					this.http.toast(res.msg)
					setTimeout(() => {
						uni.navigateBack(1)
					}, 1000)
				} else {
					this.http.toast(res.msg)
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
// 搜索框
	.searchBox {
		height: 70rpx;
		background: #FFFFFF;
		border-radius: 65rpx 65rpx 65rpx 65rpx;
		border: 1rpx solid #FFFFFF;
		padding: 0 5rpx 0 30rpx;
		position: relative;
		z-index: 100;

		.searchBtn {
			width: 124rpx;
			height: 62rpx;
			line-height: 62rpx;
			text-align: center;
			background: linear-gradient(312deg, #F8CF39 0%, #F8DA44 100%);
			border-radius: 65rpx 65rpx 65rpx 65rpx;
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #000000;
		}
	}
</style>